package com.atguigu;

import com.atguigu.mapper.UserMapper;
import com.atguigu.pojo.User;
import com.atguigu.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

//查询name=Tom的所有用户
// 查询邮箱域名为baomidou.com的所有用户
// 查询所有用户信息并按照age字段降序排序
// 查询age介于[20,30]的所有用户
// 查询age小于20或大于30的用户
// 邮箱域名为baomidou.com且年龄小于30或大于40且的用户
@SpringBootTest
public class UserMapperTest4 {
    @Autowired
    private UserService userService;
    @Test
    public void test1(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getName,"tom");
        User one = userService.getOne(wrapper);
        System.out.println(one);
    }

    @Test
    public void test2(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.likeLeft(User::getEmail,"baomidou.com");
        List<User> list = userService.list(wrapper);
        System.out.println(list);

    }

    @Test
    public void test3(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(User::getAge);
        List<User> list = userService.list(wrapper);
        System.out.println(list);
    }

    @Test
    public void test4(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.between(User::getAge,20,30);
        List<User> list = userService.list(wrapper);
        System.out.println(list);

    }

    @Test
    public void test5(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.lt(User::getAge,20).or().gt(User::getAge,30);
        for (User user : userService.list(wrapper)) {
            System.out.println(user);
        }


    }

    @Test
    public void test6(){
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.likeLeft(User::getEmail,"baomidou.com")
                .lt(User::getAge,30).or()
                .gt(User::getAge,40);
        for (User user : userService.list(wrapper)) {
            System.out.println(user);
        }


    }
}
